let express = require('express');
let router = express.Router();
// let db = require('../server/db');
let fs = require('fs');
let gm = require('gm');



/* GET users listing. */
router.get('/', function (req, res, next) {
	Db.query('SELECT * FROM user', (err, ret) => {
		res.send(ret);
	})

});
gm('./public/images/1.png')
.stroke("#ffffff")
// .drawCircle(10, 10, 20, 10)
.font(__dirname + "/../public/font/Helvetica.ttf", 30)
.drawText(0, 30, "sdasassdadassd!")
.write("./public/images/1-1.png", function (err, data) {
	if (err){
		console.log(11111111)
		console.log(err)
		// res.send(err)
	}else{
		console.log('done')
		// res.send(data)
	}
});

router.post('/login', function (req, res, next) {
	res.send('login')
});

router.post('/register', function (req, res, next) {
	gm('./public/images/1.png')
		.stroke("#ffffff")
		// .drawCircle(10, 10, 20, 10)
		.font(__dirname + "/../public/font/Helvetica.ttf", 30)
		.drawText(0, 30, "sdasassdadassd!")
		.write("./public/images/1-1.png", function (err, data) {
			if (err){
				console.log(11111111)
				console.log(err)
				res.send(err)
			}else{
				console.log('done')
				res.send(data)
			}
		});

	// fs.stat('./public/images/timg.gif', (err, data) => {
	// 	if(err){
	// 		console.log(err)
	// 		res.send(err)
	// 	}else{
	// 		console.log(data)
	// 		res.send(data)
	// 	}
	// })
	// let sql = `INSERT INTO user VALUES ('null', '${req.body.username}', '${req.body.password}')`;
	// Db.query(sql, (err, ret) => {
	// 	if(err){
	// 		console.log(err)
	// 		res.send('err');
	// 	}else{
	// 		res.send(ret);
	// 	}
	// })

});

module.exports = router;